home *** CD-ROM | disk | FTP | other *** search
- Path: lrz-muenchen.de!news
- From: watzka@stat.uni-muenchen.de (Kurt Watzka)
- Newsgroups: comp.lang.c
- Subject: Re: confusion between putchar and printf
- Date: 11 Mar 1996 21:08:26 GMT
- Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
- Distribution: world
- Message-ID: <4i24oa$9qv@sparcserver.lrz-muenchen.de>
- References: <4i1v2n$30o@news.azstarnet.com>
- NNTP-Posting-Host: sun2.lrz-muenchen.de
-
- Howard Salmon <captarm@azstarnet.com> writes:
-
- >K & R (section 1.5) states that "putchar(c) prints the contents of the
- >integer variable c as a character, usually on the screen".
-
- >Here's a small program that I wrote testing putchar. Why doesn't it
- >compile?
-
- >#include <stdio.h>
- ># define A "hello world!"
-
- >main()
- >{
- > int c;
- > c = A;
-
- Because there is no automatic conversion from "pointer to char" to "int"?
-
- "hello world" is not a char, it is a string literal, and can be
- treated like an array of char that is not const, but should not
- be modified.
-
- > putchar(A);
-
- Try:
-
- for (c = 0; A[c]; c++)
- putchar(A[c]);
- putchar('\n');
-
- or simply:
-
- puts(A);
-
- And don't forget to return something from main(), otherwise you
- will return an undefined value to the operating system.
-
- >}
-
- Kurt
- --
- | Kurt Watzka Phone : +49-89-2180-6254
- | watzka@stat.uni-muenchen.de
- | ua302aa@sunmail.lrz-muenchen.de
-
-